package com.study.utils.excel;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.text.ParseException;
import java.time.LocalDateTime;

/**
 * @author zhuzi
 * 2024/12/30 21:21
 */
public class LocalDateTimeConverter implements Converter<LocalDateTime> {


    public LocalDateTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
                                           GlobalConfiguration globalConfiguration) throws ParseException {
        DateTime parse = DateUtil.parse(cellData.getStringValue(), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd H:mm:ss", "yyyy/MM/dd H:mm");
        return parse.toLocalDateTime();
    }

    public static void main(String[] args) {
        String str = "2024/1/2 9:31";
        DateTime parse = DateUtil.parse(str, "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd H:mm:ss", "yyyy/MM/dd H:mm");
        System.out.println(parse);

    }
}

